﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Filter;
using Customer.Bussiness_Service;
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;

namespace Customer.Areas.System.Controllers
{
    [ApiController, Area("System"), Route("/[area]/Role/[action]"), Customer_Admin]
    public class roleController : ControllerBase
    {
        private readonly Irole_servier _service;
        private readonly IToole_DI _tool;
        public roleController(Irole_servier service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        } 
        #region 权限列表
        /// <summary>
        /// 获取权限列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModel<rk_role> get_pagelist(Base_List_Params query)
        {
            var result = _service.get_pagelist(query);
            return result;
        } 
        /// <summary>
        /// 管理员添加一个系统通用的角色信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel save_item(sys_role_Params query)
        {
            _tool.di_es.Add_Log("=====管理员添加一个系统通用的角色信息_请求====" + Newtonsoft.Json.JsonConvert.SerializeObject(query), "/API_Role");
            var result = _service.save_item(query);
            _tool.di_es.Add_Log("=====管理员添加一个系统通用的角色信息_结果====" + Newtonsoft.Json.JsonConvert.SerializeObject(result), "/API_Role");
            return result;
        } 
        /// <summary>
        /// 根据角色ID获取一个对应角色的详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel GetRoleModel(string rid)
        {
            var result = _service.get_model(rid);
            return result;
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel DelRole(string rid)
        {
            _tool.di_es.Add_Log("=====删除角色_请求====" + rid, "/API_Role");
            var result = _service.del_item(rid);
            _tool.di_es.Add_Log("=====删除角色_结果====" + Newtonsoft.Json.JsonConvert.SerializeObject(result), "/API_Role");
            return result;
        }
        #endregion 
        /// <summary>
        /// 绑定菜单信息到角色
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel BindMenuToRole(SaveMenuToRole query)
        {
            _tool.di_es.Add_Log("=====绑定菜单信息到角色_请求====" + Newtonsoft.Json.JsonConvert.SerializeObject(query), "/API_Role");
            var result = _service.BindMenuToRole(query);
            _tool.di_es.Add_Log("=====绑定菜单信息到角色_结果====" + Newtonsoft.Json.JsonConvert.SerializeObject(result), "/API_Role");
            return result;

        }
    }
}